<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>_${customer.customerName}_点收任务列表</title>
<script type="text/javascript">
 
  //领取任务 
  function takeTask(taskId){
	  $.ajax({
			type:'post',
			url:'${ctx}/v2_instorageCount/ajaxTakeTask',
			data:{
				taskId:taskId
			},
			dataType:'json',
			success:function(data) {
			    if(data==true){
			      //$("#queryForm").submit();
			      load();
			      myLoad();
			    }else{
			      alert(data);
			    }
			},
			error:function(data) {
				alert(data.responseText);
			}
	   });
  }
  function myLoad(){
	  $.ajax({
			type:'post',
			url:'${ctx}/v2_instorageCount/queryMyTaskList',
			data:{
				countwarehouseCode:$("#_countwarehouseCode").val(),
				countcustomerCode:$("#_countcustomerCode").val(),
				countstatus:$("#_countstatus").val(),
				countbillCode:$("#_countbillCode").val().trim()
			},
			async:false,
			dataType:'json',
			success:function(data) {
				var status=data.status;
				var content = data.content;
			    if(status=='success'){
			      $("#myTask").html('');
			      var rowNum = 1 ;
			      var str='';
			      var myTaskList=data.myTaskList;			      
			      $.each(myTaskList,function(i,t){
			    	  	if(t.bill.status=='6'){
			    	  		return true;
			    	  	}
			    	   str+="<tr><td>"+rowNum+"</td>";
			    	   rowNum++ ;
			    	   str+="<td>"+t.customer.customerName+"</td>";
			    	   str+="<td>"+t.warehouse.groupName+"</td>";
			    	   if(t.bill.billType=='customer'){
			    		   str+="<td><font color=red>采购入库</font></td>";
			    	   }else if(t.bill.billType=='allot'){
			    		   str+="<td><font color=green>调拨入库</font></td>";
			    	   }else if(t.bill.billType=='cancelOrder'){
			    		   str+="<td><font color=blue>取消单入库</font></td>";
			    	   }else if(t.bill.billType=='returnOrder'){
			    		   str+="<td><font color=black>退回件入库</font></td>";
			    	   }else if(t.bill.billType=='preOrder'){
			    		   str+="<td><font color=black>预约入库</font></td>";
			    	   }
			    	   str+="<td>"+t.billCode+"</td>";
			    	   if(t.errorFlag=='noterror'){
			    	 	  str+="<td>完好件</td>";
			    	   }else if(t.errorFlag=='error'){
			    	 	  str+="<td>破损件</td>";
			    	   }
			    	   str+="<td>"+date2str(new Date(t.createTime.time),"yyyy-MM-d h:m:s")+"</td>";
			    	   str+="<td>"+t.worker.realname+"</td>";
			    	   if(t.bill.status=='6'){
			    		   str+="<td>已取消</td>";
			    	   }else if(t.status=='undo'){
			    		   str+="<td>创建任务</td>";
			    	   }else if(t.status=='token'){
			    		   str+="<td>领取任务</td>";
			    	   }else if(t.status=='doing'){
			    		   str+="<td>点收中</td>";
			    	   }else if(t.status=='finish'){
			    		   str+="<td>完成点收</td>";
			    	   }
			    	   if(t.bill.status !='6'){
			    		   if(t.status=='token'){
				    		   str+="<td><a href=\"${ctx}/v2_instorageCount/toInstorageCountPageNew/"+t.id+"\"   class=\"btn btn-primary\" >开始点收</a></td>";
			    		   }else if(t.status=='doing'){
			    		       str+="<td><a href=\"${ctx}/v2_instorageCount/toInstorageCountPageNew/"+t.id+"\"    class=\"btn btn-primary\" >继续点收</a></td>";
			    		   }
			    	   }
			    	   str+="</tr>";
			      });
			      $("#myTask").html(str);
			    }else{
			    	alert(content);
			    }
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
	   });
  }  
  function load(){
	  $.ajax({
			type:'post',
			url:'${ctx}/v2_instorageCount/queryTaskList',
			data:{
				warehouseCode:$("#_warehouseCode").val(),
				customerCode:$("#_customerCode").val(),
			},
			async:false,
			dataType:'json',
			success:function(data) {
				var status=data.status;
				var content = data.content;
			    if(status=='success'){
			    	
			      $("#untakedTaskList").html('');
			      var rowNum = 1 ;
			      var str='';
			      var untakedTaskList=data.untakedTaskList;
			      $.each(untakedTaskList,function(i,t){
			    	   if(t.bill.status=='6'){
			    	   		return true;
			    	   }
			    	   str+="<tr><td>"+rowNum+"</td>";
			    	   rowNum++ ;
			    	   str+="<td>"+t.customer.customerName+"</td>";
			    	   str+="<td>"+t.warehouse.groupName+"</td>";
			    	   if(t.bill.billType=='customer'){
			    		   str+="<td><font color=red>采购入库</font></td>";
			    	   }else if(t.bill.billType=='allot'){
			    		   str+="<td><font color=green>调拨入库</font></td>";
			    	   }else if(t.bill.billType=='cancelOrder'){
			    		   str+="<td><font color=blue>取消单入库</font></td>";
			    	   }else if(t.bill.billType=='returnOrder'){
			    		   str+="<td><font color=black>退回件入库</font></td>";
			    	   }else if(t.bill.billType=='preOrder'){
			    		   str+="<td><font color=black>预约入库</font></td>";
			    	   }
			    	   str+="<td>"+t.billCode+"</td>";
			    	   if(t.errorFlag=='noterror'){
			    	 	  str+="<td>完好件</td>";
			    	   }else if(t.errorFlag=='error'){
			    	 	  str+="<td>破损件</td>";
			    	   }
			    	   str+="<td>"+date2str(new Date(t.createTime.time),"yyyy-MM-d h:m:s")+"</td>";
			    	   str+="<td></td>";
			    	   if(t.bill.status=='6'){
			    		   str+="<td>已取消</td>";
			    	   }else if(t.status=='undo'){
			    		   str+="<td>创建任务</td>";
			    	   }else if(t.status=='token'){
			    		   str+="<td>领取任务</td>";
			    	   }else if(t.status=='doing'){
			    		   str+="<td>点收中</td>";
			    	   }else if(t.status=='finish'){
			    		   str+="<td>完成点收</td>";
			    	   }
			    	   if(t.bill.status !='6'){
			    		   str+="<td><input type=\"button\" class=\"btn btn-primary\" onclick=\"takeTask('"+t.id+"');\" value=\"领取任务\"/></td>"
			    	   }
			    	   str+="</tr>";
			      });
			      $("#untakedTaskList").html(str);
			    }else{
			    	alert(content);
			    }
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
	   });
  }
  function date2str(x, y) {   
	  var z = {      
			  y: x.getFullYear(),      
			  M: x.getMonth() + 1,      
			  d: x.getDate(),      
			  h: x.getHours(),      
			  m: x.getMinutes(),      
			  s: x.getSeconds()   
			  };   
	  return y.replace(/(y+|M+|d+|h+|m+|s+)/g, function(v) {      
		  return ((v.length > 1 ? "0" : "0") + eval('z.' + v.slice(-1))).slice(-(v.length > 2 ? v.length : 2))   
	 });
  }
</script>
</head>

<body>
<section class="content">
              
              <div class="row">
			<div class="col-md-12">
				<div class="box box-solid box-primary">
					<div class="box-header">
					    <i class="fa fa-list"></i>
                        <h3 class="box-title">  我的点收任务</h3>
						<div class="box-tools pull-right">
							<button class="btn btn-primary btn-sm" data-widget="collapse">
								<i class="fa fa-minus"></i>
							</button>
						</div>
					</div>
					<div class="box-body">
<%-- 					 <form class="form-search" id="countqueryForm" method="post" action="${ctx}/v2_instorageCount/queryTaskList" style="margin-top: 10px;">
 --%>						<div class="form-group row">
							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text"> 商家用户： </span> 
									<select class="form-control required"  id="_countcustomerCode" name="_countcustomerCode"    onchange="ajaxAreaGroup(this,'_countwarehouseCode');" style="width: 100px;" >
									        <option value=""></option>
											<c:forEach items="${countcustomerCodeList}" var="customer">
												<option value="${customer.customerCode}"
												  <c:if test="${countcustomerCode eq customer.customerCode }">selected=selected</c:if>
												>${customer.customerName}</option>
											</c:forEach>
									</select> 
								</div>
							</div>
								
							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text">作业仓库： </span> 
									<select  name="_countwarehouseCode"  id="_countwarehouseCode"   class="form-control" >
										<option value=""></option>
										<c:forEach items="${countwarehouseList}" var="w" >
										   <option value="${w.groupCode}" 
										   <c:if test="${countwarehouseCode eq w.groupCode }">selected=selected</c:if>
										   >${w.groupName}</option>
									   </c:forEach>
									</select>
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text">状态： </span> 
									<select  name="_countstatus"  id="_countstatus" class="form-control"  >
										<option value="" <c:if test="${countstatus eq ''}">selected=selected</c:if> ></option>
									    <option value="token" <c:if test="${countstatus eq 'token'}">selected=selected</c:if> >领取任务</option>
									    <option value="doing" <c:if test="${countstatus eq 'doing'}">selected=selected</c:if> >点收中</option>
									</select>
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text">入库单号： </span> 
									<input type="text" name="_countbillCode" id="_countbillCode"  class="form-control" />
								</div>
							</div>
							<div class="col-sm-9">
							 <button class="btn btn-primary"  style="margin-left: 10px; " onclick="myLoad();">搜索</button>
							</div>
						</div>
					<!-- </form> -->
					 <table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			    <th>序号</th>
			    <th>商家</th>
			    <th>作业仓库</th>
			    <th>入库类型</th>
			    <th>入库单号</th>
			    <th>商品类型</th>
			    <th>创建时间</th>
			    <th>任务执行人</th>
			    <th>任务状态</th>
			    <th>操作</th>
			</tr></thead>
		<tbody id="myTask" >
		<c:forEach items="${myTaskList}" var="t" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			   <td>${t.customer.customerName}</td>
			   <td>${t.warehouse.groupName}</td>
			   <td>
				  <c:if test="${t.bill.billType eq 'customer' }"><font color=red>采购入库</font></c:if> 
				  <c:if test="${t.bill.billType eq 'allot' }"><font color=green>调拨入库</font></c:if>
				  <c:if test="${t.bill.billType eq 'cancelOrder' }"><font color=blue>取消单入库</font></c:if>
				  <c:if test="${t.bill.billType eq 'returnOrder' }"><font color=black>退回件入库</font></c:if>
				  <c:if test="${t.bill.billType eq 'preOrder' }"><font color=black>预约入库</font></c:if>
			   </td>
			   <td>${t.billCode}</td>
				<td>
				    <c:if test="${t.errorFlag eq 'error' }"><font color=red>报损件</font></c:if> 
				    <c:if test="${t.errorFlag eq 'noterror' }">完好件</c:if> 
				</td>
			   <td>${fn:substring(t.createTime,0,19)}</td>
			   <td>${t.worker.realname}</td>
			    <td>
			    <c:choose>
			    	<c:when test="${t.bill.status eq '6' }">已取消</c:when>
			    	<c:otherwise>
				    	<c:if test="${t.status eq 'undo'}">创建任务</c:if>
				     	<c:if test="${t.status eq 'token'}">领取任务</c:if>
				     	<c:if test="${t.status eq 'doing'}">点收中</c:if>
				     	<c:if test="${t.status eq 'finish'}">完成点收</c:if>
			    	</c:otherwise>
			    </c:choose>
			   </td>
			   <td>
				   <c:if test="${t.bill.status ne '6' }">
				      <c:if test="${t.status eq 'token'}">
				        <a href="${ctx}/v2_instorageCount/toInstorageCountPageNew/${t.id}"   class="btn btn-primary" >开始点收</a>
				      </c:if>
				      <c:if test="${t.status eq 'doing'}">
				        <a href="${ctx}/v2_instorageCount/toInstorageCountPageNew/${t.id}"   class="btn btn-primary" >继续点收</a>
				      </c:if>
			      </c:if>
			   </td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
					</div>
				</div>
			</div>
		</div>

	
	
	<!-- 未分配的任务 -->
	 <div class="row">
			<div class="col-md-12">
				<div class="box box-solid box-primary">
					<div class="box-header">
					    <i class="fa fa-list"></i>
                        <h3 class="box-title"> 未分配任务</h3>
						<div class="box-tools pull-right">
							<button class="btn btn-primary btn-sm" data-widget="collapse">
								<i class="fa fa-minus"></i>
							</button>
						</div>
					</div>
					<div class="box-body">
					  <!-- <form class="form-search" id="queryForm" method="post"  style="margin-top: 10px;"> -->
						<div class="form-group row">

							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text"> 商家用户： </span> 
									<select class="form-control required"  id="_customerCode" name="_customerCode" onchange="ajaxAreaGroup(this,'_warehouseCode');" style="width: 100px;" >
				        <option value=""></option>
						<c:forEach items="${customerList}" var="customer">
							<option value="${customer.customerCode}"
							  <c:if test="${customerCode eq customer.customerCode }">selected=selected</c:if>
							>${customer.customerName}</option>
						</c:forEach>
				</select> 

								</div>
							</div>
								
							<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
									<span class="input-group-text">作业仓库： </span> 
									<select  name="_warehouseCode"  id="_warehouseCode" class="form-control" >
					<option value=""></option>
					<c:forEach items="${warehouseList}" var="w" >
					   <option value="${w.groupCode}" 
					   <c:if test="${warehouseCode eq w.groupCode }">selected=selected</c:if>
					   >${w.groupName}</option>
				   </c:forEach>
				</select>

								</div>
							</div>
							<div class="col-sm-6">
							 <button class="btn btn-primary"  style="margin-left: 10px; " onclick="load();">搜索</button>
							</div>
						</div>
							<!-- </form> -->
								<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
		<tr>
			    <th>序号</th>
			    <th>商家</th>
			    <th>作业仓库</th>
			    <th>入库类型</th>
			    <th>入库单号</th>
			     <th>商品类型</th>
			    <th>创建时间</th>
			    <th>任务执行人</th>
			    <th>任务状态</th>
			    <th>操作</th>
			</tr>
			</thead>
		<tbody id="untakedTaskList">
		<c:forEach items="${untakedTaskList}" var="t" varStatus="i">
			<c:if test="${t.bill.status != '6' }">
			<tr>
			    <td>${i.count}</td>
			   <td>${t.customer.customerName}</td>
			   <td>${t.warehouse.groupName}</td>
			   <td>
				  <c:if test="${t.bill.billType eq 'customer' }"><font color=red>采购入库</font></c:if> 
				  <c:if test="${t.bill.billType eq 'allot' }"><font color=green>调拨入库</font></c:if>
				  <c:if test="${t.bill.billType eq 'cancelOrder' }"><font color=blue>取消单入库</font></c:if>
				  <c:if test="${t.bill.billType eq 'returnOrder' }"><font color=black>退回件入库</font></c:if>
				  <c:if test="${t.bill.billType eq 'preOrder' }"><font color=black>预约入库</font></c:if>
			   </td>
			   <td>${t.billCode}</td>
			   <td>
				    <c:if test="${t.errorFlag eq 'error' }"><font color=red>报损件</font></c:if> 
				    <c:if test="${t.errorFlag eq 'noterror' }">完好件</c:if> 
				</td>
			   <td>${fn:substring(t.createTime,0,19)}</td>
			   <td>${t.worker.realname}</td>
			   <td>
			   <c:choose>
					<c:when test="${t.bill.status eq '6' }">已取消</c:when>
					<c:otherwise>
						<c:if test="${t.status eq 'undo'}">创建任务</c:if>
						<c:if test="${t.status eq 'token'}">领取任务</c:if>
						<c:if test="${t.status eq 'doing'}">点收中</c:if>
						<c:if test="${t.status eq 'finish'}">完成点收</c:if>
					</c:otherwise>
				</c:choose>
				</td>
			   <td>
			   		<c:if test="${t.bill.status ne '6' }">
			      		<input type="button" class="btn btn-primary" onclick="takeTask('${t.id}');" value="领取任务"/>
			      	</c:if>
			   </td>
			</tr>
			</c:if>
		</c:forEach>
		</tbody>
		
	</table>
					</div>
				</div>
			</div>
		</div>
			
	

	
</section>
</body>
</html>
